﻿using System;
using System.ComponentModel.DataAnnotations;
using RapidCMS.Core.Abstractions.Data;

namespace RapidCMS.Example.Shared.Data
{
    public class User : IEntity, ICloneable
    {
        public int Id { get; set; }
        public string? Name { get; set; }
        public DateTime? StartDate { get; set; }

        [Required]
        // the horror
        [RegularExpression("^((?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])|(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[^a-zA-Z0-9])|(?=.*?[A-Z])(?=.*?[0-9])(?=.*?[^a-zA-Z0-9])|(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^a-zA-Z0-9])).{8,}$",
            ErrorMessage = "Passwords must be at least 8 characters and contain at 3 of 4 of the following: upper case (A-Z), lower case (a-z), number (0-9) and special character (e.g. !@#$%^&*)")]
        public string? Password { get; set; }

        [Required]
        public string? FileBase64 { get; set; }

        public string? ProfilePictureBase64 { get; set; }

        public int Integer { get; set; }
        public double Double { get; set; }

        string? IEntity.Id { get => Id.ToString(); set => Id = int.Parse(value ?? "0"); }

        public object Clone()
        {
            return new User
            {
                Id = Id,
                Name = Name,
                Password = Password,
                Double = Double,
                FileBase64 = FileBase64,
                ProfilePictureBase64 = ProfilePictureBase64,
                Integer = Integer,
                StartDate = StartDate
            };
        }
    }
}
